<template>
    <div id="appraisalCompany">
      <van-tabs v-model="active" @click="handleclickto" :active="active" swipeable>
        <van-tab title="镇街排查" v-if="showzjxx">
          <div style="padding: 10px;">
            <house-safety-checklist ref="houseSafety" v-if="objectNo" :objectNo="objectNo" :disabled="true">
            </house-safety-checklist>
          </div>
        </van-tab>
        <van-tab title="选择鉴定公司">
          <div style="padding: 4px">
            <van-search v-model="QYMC" style="border-radius: 10px; height: 44px" background="#f7f8fa"
                        placeholder="请输入搜索关键词" @search="onSearch" />
            <!--<form action="/">-->
              <!---->
              <!--<intut style="-->
            <!--width: calc(100% - 120px);-->
            <!--background: #eee;-->
            <!--border-radius: 10px;-->
            <!--height: 40px;-->
            <!--font-size: 14px;-->
            <!--float: left;"-->
                          <!--show-action-->
                          <!--v-model="QYMC" placeholder="请输入企业名称" @click="onSearch"/>-->
            <!--</form>-->
            <span style="
          width: 120px;
          height: 40px;
          display: inline-block;
          line-height: 40px;
          text-align: center;
        ">共计：{{ JDGSData.length }}家</span>
          </div>
          <div style="height: 72vh;overflow:auto;">
            <van-field
              readonly
              clickable
             name="picker"
              clear-trigger
              :value="JDJG"
              label="注册地"
              placeholder="请选择注册地"
            @click="showJDGS = true"
             />
            <!--<van-cell is-link @click="showJDGS=true"></van-cell>-->
            <van-popup v-model="showJDGS" position="bottom" get-container="#popup">
            <van-picker
              show-toolbar
              :columns="cityData"
              value-key="cityname"
              @confirm="onConfirmJDGS"
              @cancel="showJDGS = false"
            />
            </van-popup>
            <van-list   finished-text="没有更多了">
              <van-cell v-for="(item, index) in JDGSData"  :key="index">
                <ul>
                  <li>
                    <p style="font-weight: bold; margin-bottom: 8px; height: 3vh">
                      <img @click="changeData(item)" v-if="!item.checked" src="https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/WXZ.png">
                      <img @click="changeData(item)" v-if="item.checked" src="https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/XZ.png">
                      <!--<van-checkbox  v-model="item.checked">{{item.qymc}}</van-checkbox>-->
                      <span style>{{item.qymc}}</span>
                    </p>
                    <p style="font-size: 14px; color: #848484">
                      <span style="float: left">注册地：{{ item.cityName }}</span>
                      <span style="float: right">企业信用码：{{ item.zzjgdm }}</span>
                    </p>
                    <p style="clear: both; display: flex; align-items: center;font-size: 14px; color: #848484">
                      <span style="float: left">法人：{{ item.frxm }}</span>
                    </p>
                    <p style="clear: both; display: flex; align-items: center;font-size: 14px; color: #848484">
                      <span style="float: left">通讯地址：{{ item.dwdz }}</span>
                    </p>
                  </li>
                </ul>
              </van-cell>
            </van-list>
          </div>
          <!--<van-field-->
            <!--readonly-->
            <!--clickable-->
            <!--name="picker"-->
            <!--:value="JDJG"-->
            <!--label="公司名称"-->
            <!--placeholder="请选择鉴定公司"-->
            <!--@click="showJDGS = true"-->
          <!--/>-->
          <!--<van-popup v-model="showJDGS" position="bottom" get-container="#popup">-->
            <!--<van-picker-->
              <!--show-toolbar-->
              <!--:columns="JDGSData"-->
              <!--value-key="qymc"-->
              <!--@confirm="onConfirmJDGS"-->
              <!--@cancel="showJDGS = false"-->
            <!--/>-->
          <!--</van-popup>-->
          <div style="position:fixed;bottom: 10px;width: 100%;">
            <!--<span class="bottomBtn" @click="SaveData">保存</span>-->
            <span class="bottomBtn" @click="SaveData(true)">提交</span>
          </div>
        </van-tab>
      </van-tabs>
    </div>
</template>

<script>
  import { FileServerProxy ,saveAuthInfo,appraisal,objectNoTransfer,selectTechnicalList,GetAdministrative} from "@/utils/api";
  import patrolInformation from "../../activity/ZDPC/formPanel/patrolInformation";
  import houseSafetyChecklist from "../../activity/ZDPC/formPanel/houseSafetyChecklist";
  import {Dialog }  from "vant";
  export default {
    name: "appraisalCompany",
    data(){
      return{
        showzjxx:true,
        loading: false,
        finished: false,
        QYMC: '',
        objectNo:"",
        active:2,
        JDJG:'',
        uscc:'',
        showJDGS:false,
        JDGSData:[
          // {
          //   COMAPNY_NAME: '杭州恒信电气有限公司',
          //   TYSHXYDM: '913301857471537181',
          // },
        ],
        rowData:{},
        cityData: '',
        citycode: '',
        JDJGS: ''
      }
    },
    methods:{
      handleclickto(){

      },
      onSearch() {
        debugger
        this.getJDGSData()
      },
      changeData(data) {
        this.JDGSData.forEach((item,index) =>{
          if (data.id == item.id) {
            item.checked  = true
            this.JDJGS = item.qymc
            this.uscc = item.zzjgdm
            this.$forceUpdate()
          } else {
            item.checked  = false
            this.$forceUpdate()
          }
          // this.$forceUpdate()
        })
      },
      getJDGSData: async function () {
        let param={
          "belongCountryList":[],
          "belongCountyList":this.citycode?[this.citycode]:[],
          "name":this.QYMC,
          "pageNo":1,
          "fwlx": "鉴定机构",
          //"qymc": this.QYMC,
          "pageSize":100000,
          "cityCode": '',
          "token":null
        };
        const res = await  selectTechnicalList(param);
        if(res.data&&res.data.data&&res.data.data.pageList.length>0){
          this.JDGSData = res.data.data.pageList;
          this.JDGSData.forEach((item,index) =>{
            item.checked = false
            this.$forceUpdate()
          })
        }else{
          this.JDGSData = [];
        }

        //   var params = {
        //     accessCode: '2caf341e427cb1252dd89c8a7bbf0f75',
        //     cityCode: this.rowData.cityByCode,
        //     params: {
        //       dataguid: '69f6523e-0a8e-41bc-89f2-48573b917a77',
        //       searchObject: JSON.stringify([
        //         { field: 'FWQY', value: this.rowData.cityByCode },
        //         { field: 'FWLX', value: 447 },
        //       ]),
        //       token: window.localStorage.getItem('token'),
        //     },
        //   }
        // const res = await FileServerProxy(params)
        // if (res.data.data != {}) {
        //   let data = JSON.parse(res.data.data).Data
        //   console.log(data)
        //   if (data) {
        //     this.JDGSData = data
        //   }
        // } else {
        //   this.JDGSData = []
        // }
      },
      getCityData: async function() {
        var res1 = await GetAdministrative("330000000000")
        console.log(res1)
        this.cityData = res1.data.data
        this.cityData.push({
          cityname:'',
          citycode:''
        })

      },
      onConfirmJDGS(data) {
        this.JDJG = data.cityname
        this.citycode = data.citycode
        this.showJDGS = false
        this.getJDGSData()
      },
      SaveData: async function(item){
        if(!this.JDJGS){
          this.$toast.fail("请选择鉴定公司！")
          return;
        }
        Dialog.confirm({
          message: `您当前选择的鉴定公司是${this.JDJGS},是否确认提交`,
        })
          .then(async() => {
            // on confirm
            let param = {
              objectNo: this.rowData,
              isAuth: '否',
              recheck: 0,
              // authLevel: '',
              authCompanyName: this.JDJGS,
              socialCreditCode: this.uscc,
            }
            const res = await saveAuthInfo(param);
            if (item==true) {
              let params1 = {
                objectNo: this.rowData,
                userName: window.localStorage.getItem('DanDianName'),
                authCompanyName: this.JDJG,
                socialCreditCode: this.uscc,
                recheck: 0,
                token: window.localStorage.getItem('token'),
                isAuth: '否',
                // authLevel: 'D',
              }
              const res1 = await appraisal(params1)
              console.log(res1)
              if (res1.data.data) {
                this.$router.push({
                  path: '/ZLJIndex',
                })
              } else {
                this.$toast.fail(res1.data.msg)
              }
            }else{
              if (res.data.data){
                this.$toast.success("保存成功！")
              }
            }
          })
          .catch(() => {

            // on cancel
          });

      },
      getDangerZJPCList:async function(){
       const  NoTransfer=await objectNoTransfer(this.rowData);
       if(NoTransfer.data.data){
         this.showzjxx=true;
         debugger
         this.objectNo=NoTransfer.data.data;
         //测试是不是不支持props传参
         window.sessionStorage.setItem('objectNo',this.objectNo)
       }else{
         this.showzjxx=false;
       }
      },
    },
    mounted(){
      //通过危改的objtctNo 获取安全的objectNo
      if (this.$route.query.data){
        this.rowData = this.$route.query.data
        this.getDangerZJPCList();
      }
      // console.log(JSON.parse(this.$route.query.data))
      this.getJDGSData()
      this.getCityData()
    },
    components: {
      patrolInformation,
      houseSafetyChecklist
    },
  };
</script>

<style scoped lang="scss">
#appraisalCompany{
  width: 100%;
  height: 100vh;
  padding: 10px;
  .bottomBtn {
    width: 95%;
    height: 40px;
    background: #007aff;
    line-height: 40px;
    text-align: center;
    color: #ffffff;
    font-weight: bold;
    display: inline-block;
  }
}
</style>
